package night;

import java.io.File;

public class 九一File {
    public static void main(String[] args) {
        File src = new File("D:\\IdeaProjects\\JavaSEProject\\gg.txt");
        System.out.println("名字: " + src.getName());
        System.out.println("路径: " + src.getPath());
        System.out.println("绝对路径: " + src.getAbsolutePath());
        System.out.println("父路径: " + src.getParent());
        System.out.println("父文件: " + src.getParentFile().getName());
        System.out.println("是否存在: " + src.exists());
        System.out.println("是否文件: " + src.isFile());
        System.out.println("是否文件夹: " + src.isDirectory());

        if (src == null || !src.exists()) {
            System.out.println("文件不存在");
        } else if (src.isFile()) {
            System.out.println("是文件");
        } else {
            System.out.println("是文件夹");
        }

        System.out.println(src.length());

        File src1 = new File("text");
        System.out.println(src1.length());

        File src2 = new File("D:/IdeaProjects/JavaSEProject/dir/study");
        System.out.println(src2.mkdir());
        System.out.println(src2.mkdirs());

        File src3 = new File("D:/IdeaProjects/JavaSEProject");
        for (String s : src3.list()) {
            System.out.println(s);
        }
        for (File file : src3.listFiles()) {
            System.out.println(file.getAbsolutePath());
        }
        for (File file : src3.listRoots()) {
            System.out.println(file.getAbsolutePath());
        }
        printName(src3, 0);
    }

    public static void printName(File src, int level) {
        for (int i = 0; i < level; i++) {
            System.out.print("-");
        }
        System.out.println(src.getName());
        if (null == src || !src.exists()) {
            return;
        } else if (src.isDirectory()) {
            for (File file : src.listFiles()) {
                printName(file, level + 1);
            }
        }
    }
}
